﻿using System;
using MessageRouter.Configuration;

namespace MessageRouter
{
    public abstract class MessageWriter : IObserver<RoutedMessage>
    {
        private readonly string name;
        private readonly Uri address;

        private bool inSubscription;

        protected MessageWriter() { }

        public MessageWriter(WriterConfigurationElement config)
        {
            this.name = config.Name;
            this.address = config.Address;
            this.inSubscription = false;
        }

        public string Name
        {
            get { return this.name; }
        }

        public Uri Address
        {
            get { return this.address; }
        }

        internal bool InSubscription
        {
            get { return this.inSubscription; }
            set { this.inSubscription = value; }
        }

        public virtual void OnCompleted() { }
        public virtual void OnError(Exception error) { }
        public virtual void OnNext(RoutedMessage value) { }
        public virtual void Open() { }
        public virtual void Close() { }
    }
}
